BACKGROUND IN BRIEF
Documents can be assigned to a particular Material in Material Master and as well as in BOM.
1) MM03 – To View Documents in Material Master
2) CS03 – To View Documents in BOM
Suppose in a report we need to display all these documents against a particular Material.
We need two separate logic for this which are listed below.
1) Fetching the documents assigned in Material Master (MM01/MM02)
2) Fetching the documents assigned in BOM (CS01/CS02)
We will get the document list in DRAD table where we will get details like Document Type, Document Number, Document Version, etc.
1) Documents assigned in Material Master (MM01/MM02)
Pass ‘MARA’ in DOKOB field and material number in OBJKY field.
We may face a problem here.
The data type of MATNR is 18 character but this OBJKY field is 50 character.
The easiest solution is…
We can keep another column of type DRAD-OBJKY in the same internal table where we have the list of all the materials.
Run a loop and convert the material number from 18 character to 50 character.
After this use SELECT Query to fetch data from DRAD table using FOR ALL ENTRIES with the new prepared column having material number of length 50 characters.
2) Documents assigned in BOM (CS01/CS02)
Step B: Then we will fetch the Guid(GUIDX) of the that BOM Material from STKO table by passing BOM category(STLTY) as ‘M’ and the BOM Number(STLNR) we got in Step A into BOM(STLNR) of STKO Table. We pass ‘M’ into BOM category(STLTY) because here we are concerned only about Material BOM.
Step C: Now, we need to fetch the documents from DRAD table by passing the Guid(GUIDX) we got in Step B into the Object key(OBJKY) field in DRAD table.
Now while programming we may face a problem. The data type of GUIDX field in STKO table is RAW(length = 16) and the data type of OBJKY in DRAD table is CHAR(Length = 50). We won’t be able to apply FOR ALL ENTRIES in the select query directly.
A normal assignment statement won’t do your job here. So, we should use this function module to do it.
This function module will convert the data from RAW type to CHAR type.
CALL FUNCTION ‘GUID_CONVERT‘
iv_guid_x16 = guid_inp
ev_guid_c32 = guid_out
no_unicode_support_yet = 1
parameters_error = 2
OTHERS = 3.
Store the new converted GUIDX which is character type in a separate table and apply FOR ALL ENTRIES with that separate table when fetching data from DRAD table.
We will get our desired results in this way.