2020 Nov 23 6:01 PM
HI EXPERT
When I want my description material to be displayed in Chinese, but if the material does not have Chinese description material displayed instead of the null description material, I wrote the following code, but I get an error that I displayed at the bottom of the code.
TYPE-POOLS SLIS.
TYPES : BEGIN OF TY_T023T ,
MATKL TYPE T023T-MATKL,
WGBEZ TYPE T023T-WGBEZ,
END OF TY_T023T.
DATA : IT_T023T TYPE STANDARD TABLE OF TY_T023T .
DATA : I_T023T TYPE TY_T023T .
TYPES : BEGIN OF TY_T001W ,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_T001W.
DATA : IT_T001W TYPE STANDARD TABLE OF TY_T001W .
DATA : I_T001W TYPE TY_T001W .
TYPES : begin of TY_marafinal ,
matnr like ZSTR_MARAFINAL-matnr ,
maktx like ZSTR_MARAFINAL-maktx ,
werks like ZSTR_MARAFINAL-WERKS ,
matkl like ZSTR_MARAFINAL-MATKL ,
wgbez like ZSTR_MARAFINAL-WGBEZ ,
name1 like ZSTR_MARAFINAL-name1,
cellcolor TYPE lvc_t_scol ,
end of TY_marafinal.
DATA : IT_MARAFINAL TYPE STANDARD TABLE OF TY_MARAFINAL,
I_MARAFINAL TYPE TY_MARAFINAL .
DATA : IDX TYPE I .
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV.
DATA : IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA :IT_CELLCOLOR TYPE LVC_S_SCOL.
SELECT-OPTIONS : S_MATNR FOR I_MARAFINAL-MATNR.
SELECT-OPTIONS : S_WERKS FOR I_MARAFINAL-WERKS.
SELECT-OPTIONS : S_MATKL FOR I_MARAFINAL-MATKL.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM VALIDATE_FCAT.
PERFORM VALIDATE_LAYOUT .
END-OF-SELECTION.
PERFORM DISPLAY_ALV.
FORM GET_DATA.
SELECT MARA~MATNR, MAKT~MAKTX,
MARC~WERKS, MARA~MATKL
INTO CORRESPONDING FIELDS OF TABLE @IT_MARAFINAL
FROM MARA
left outer JOIN MAKT ON MAKT~MATNR = MARA~MATNR
INNER JOIN MARC ON MARC~MATNR = MARA~MATNR
AND MAKT~MATNR = MARC~MATNR
WHERE MARA~MATNR IN @S_MATNR
AND MARA~MATKL IN @S_MATKL
AND MARC~WERKS IN @S_WERKS
AND MAKT~SPRAS = '1'.
SORT IT_MARAFINAL BY MATNR .
IF IT_MARAFINAL[] IS NOT INITIAL .
SELECT T001W~WERKS T001W~NAME1
INTO TABLE IT_T001W
FROM T001W
FOR ALL ENTRIES IN IT_MARAFINAL
WHERE WERKS = IT_MARAFINAL-WERKS AND SPRAS EQ '1'.
SELECT T023T~MATKL T023T~WGBEZ
INTO TABLE IT_T023T
FROM T023T
FOR ALL ENTRIES IN IT_MARAFINAL
WHERE MATKL = IT_MARAFINAL-MATKL AND SPRAS EQ '1'.
LOOP AT IT_MARAFINAL[] INTO I_MARAFINAL .
IT_cellcolor-fname = 'MATNR'.
IT_cellcolor-color-col = 4.
IT_cellcolor-color-int = '1'.
IT_cellcolor-color-inv = '0'.
APPEND IT_cellcolor TO I_MARAFINAL-cellcolor.
CLEAR: IT_cellcolor.
IT_cellcolor-fname = 'MAKTX'.
IT_cellcolor-color-col = 4.
IT_cellcolor-color-int = '1'.
IT_cellcolor-color-inv = '0'.
APPEND IT_cellcolor TO I_MARAFINAL-cellcolor.
CLEAR: IT_cellcolor.
READ TABLE IT_T001W INTO I_T001W
WITH KEY WERKS = I_MARAFINAL-WERKS.
I_MARAFINAL-NAME1 = I_T001W-NAME1 .
READ TABLE IT_T023T INTO I_T023T
WITH KEY MATKL = I_MARAFINAL-MATKL .
I_MARAFINAL-WGBEZ = I_T023T-WGBEZ .
IDX = SY-TABIX.
MODIFY IT_MARAFINAL[] FROM I_MARAFINAL INDEX IDX .".TRANSPORTING cellcolor.
ENDLOOP.
ENDIF.
ENDFORM.
FORM DISPLAY_ALV.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
is_layout = IT_layout
IT_FIELDCAT = IT_FCAT[]
TABLES
T_OUTTAB = IT_MARAFINAL.
ENDFORM.
FORM VALIDATE_FCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
* I_INTERNAL_TABNAME = 'IT_MARAFINAL'
I_structure_name = 'ZSTR_MARAFINAL'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = IT_FCAT.
ENDFORM.
FORM VALIDATE_LAYOUT .
CLEAR IT_layout.
IT_layout-colwidth_optimize = 'X'. " Optimization of Col width
IT_layout-coltab_fieldname = 'CELLCOLOR'.
ENDFORM.
ERORR :
ERROR IN ABAP STATMENT WHILE PROCESSING AN INTERNAL TABLE
THANK YOU FOR YOUR HELPS
2020 Nov 24 7:32 AM
I guess you mean your LEFT OUTER JOIN on the material description table (MAKT) doesn't work well, it behaves like an INNER JOIN.
It's because the condition on the language should not be in the WHERE but in the ON, like this:
SELECT MARA~MATNR, MAKT~MAKTX,
MARC~WERKS, MARA~MATKL
INTO CORRESPONDING FIELDS OF TABLE @IT_MARAFINAL
FROM MARA
left outer JOIN MAKT ON MAKT~MATNR = MARA~MATNR
AND MAKT~SPRAS = '1' "<============ move it here
INNER JOIN MARC ON MARC~MATNR = MARA~MATNR
"""AND MAKT~MATNR = MARC~MATNR "<============ remove it
WHERE MARA~MATNR IN @S_MATNR
AND MARA~MATKL IN @S_MATKL
AND MARC~WERKS IN @S_WERKS.
What the SQL does with a join/on and a where, from the user perspective, is that it first does the JOIN and ON, then it applies the WHERE on the joined result.
As a rule-of-thumb, it makes no sense to have a WHERE condition on a LEFT OUTER JOIN table. But sometimes it can make sense to use IS NULL if you want a different WHERE condition whether the join has 0 line in the joined table (joined columns are null) or 1+ lines (joined columns are then usually not null).
2020 Nov 23 6:45 PM
I gave you detailed instructions on how to format your code when you post here: https://answers.sap.com/questions/13195563/empty-result-1.html
When you start doing that, then I may start looking at your questions and possibly answering them.
2020 Nov 23 7:32 PM
Please use the CODE button to format your code. I still can't read your code as it's so badly presented.
2020 Nov 23 8:17 PM
afsane_salehi,
As already informed by others your question will never be answered if its not presented well, kindly use the CODE option and present it in readable format.
There are lo of mistakes in your Coding, you have mentioned where condition for field SPRAS by feeding the value 1 which is not right. I hope you won't get any entry in your internal table.
Your Type Declaration does not look right, you are trying to append the field catalog to a wrong field.
Most of your statements are not right, Not sure on your requirement.
Recommend you to first go through few basic tutorial and the start coding.
Regards!
2020 Nov 24 5:47 AM
THANK YOU matthew.billinghamsandra.rossisatishkumarbalasubramanian
I finally found the code button
I just started a month of Abap training and I must have made many mistakes ,The first thing that was important to me in this code is not to use Inner Join more than 3 times And my catalog field must not be filled in manually To do this, I used the number one for SPRAS, which shows the number in the table T002 in Chinese's .
TYPE-POOLS SLIS.
TYPES : BEGIN OF TY_T023T ,
MATKL TYPE T023T-MATKL,
WGBEZ TYPE T023T-WGBEZ,
END OF TY_T023T.
DATA : IT_T023T TYPE STANDARD TABLE OF TY_T023T .
DATA : I_T023T TYPE TY_T023T .
TYPES : BEGIN OF TY_T001W ,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_T001W.
DATA : IT_T001W TYPE STANDARD TABLE OF TY_T001W .
DATA : I_T001W TYPE TY_T001W .
TYPES : begin of TY_marafinal ,
matnr like ZSTR_MARAFINAL-matnr,
maktx like ZSTR_MARAFINAL-maktx,
werks like ZSTR_MARAFINAL-WERKS,
matkl like ZSTR_MARAFINAL-MATKL,
wgbez like ZSTR_MARAFINAL-WGBEZ,
name1 like ZSTR_MARAFINAL-name1,
cellcolor TYPE lvc_t_scol,
end of TY_marafinal.
DATA : IT_MARAFINAL TYPE STANDARD TABLE OF TY_MARAFINAL,
I_MARAFINAL TYPE TY_MARAFINAL.
DATA : IDX TYPE I .
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV.
DATA : IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA :IT_CELLCOLOR TYPE LVC_S_SCOL.
SELECT-OPTIONS : S_MATNR FOR I_MARAFINAL-MATNR.
SELECT-OPTIONS : S_WERKS FOR I_MARAFINAL-WERKS.
SELECT-OPTIONS : S_MATKL FOR I_MARAFINAL-MATKL.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM VALIDATE_FCAT.
PERFORM VALIDATE_LAYOUT .
END-OF-SELECTION.
PERFORM DISPLAY_ALV.
FORM GET_DATA.
SELECT MARA~MATNR, MAKT~MAKTX,
MARC~WERKS, MARA~MATKL
INTO CORRESPONDING FIELDS OF TABLE @IT_MARAFINAL
FROM MARA
left outer JOIN MAKT ON MAKT~MATNR = MARA~MATNR
INNER JOIN MARC ON MARC~MATNR = MARA~MATNR
AND MAKT~MATNR = MARC~MATNR
WHERE MARA~MATNR IN @S_MATNR
AND MARA~MATKL IN @S_MATKL
AND MARC~WERKS IN @S_WERKS
AND MAKT~SPRAS = '1'.
SORT IT_MARAFINAL BY MATNR .
IF IT_MARAFINAL[] IS NOT INITIAL .
SELECT T001W~WERKS T001W~NAME1
INTO TABLE IT_T001W
FROM T001W
FOR ALL ENTRIES IN IT_MARAFINAL
WHERE WERKS = IT_MARAFINAL-WERKS AND SPRAS EQ '1'.
SELECT T023T~MATKL T023T~WGBEZ
INTO TABLE IT_T023T
FROM T023T
FOR ALL ENTRIES IN IT_MARAFINAL
WHERE MATKL = IT_MARAFINAL-MATKL AND SPRAS EQ '1'.
LOOP AT IT_MARAFINAL[] INTO I_MARAFINAL .
IT_cellcolor-fname = 'MATNR'.
IT_cellcolor-color-col = 4.
IT_cellcolor-color-int = '1'.
IT_cellcolor-color-inv = '0'.
APPEND IT_cellcolor TO I_MARAFINAL-cellcolor.
CLEAR: IT_cellcolor.
IT_cellcolor-fname = 'MAKTX'.
IT_cellcolor-color-col = 4.
IT_cellcolor-color-int = '1'.
IT_cellcolor-color-inv = '0'.
APPEND IT_cellcolor TO I_MARAFINAL-cellcolor.
CLEAR: IT_cellcolor.
READ TABLE IT_T001W INTO I_T001W
WITH KEY WERKS = I_MARAFINAL-WERKS.
I_MARAFINAL-NAME1 = I_T001W-NAME1 .
READ TABLE IT_T023T INTO I_T023T
WITH KEY MATKL = I_MARAFINAL-MATKL .
I_MARAFINAL-WGBEZ = I_T023T-WGBEZ .
IDX = SY-TABIX.
MODIFY IT_MARAFINAL[] FROM I_MARAFINAL INDEX IDX .
ENDLOOP.
ENDIF.
ENDFORM.
FORM DISPLAY_ALV.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
is_layout = IT_layout
IT_FIELDCAT = IT_FCAT[]
TABLES
T_OUTTAB = IT_MARAFINAL.
ENDFORM.
FORM VALIDATE_FCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_structure_name = 'ZSTR_MARAFINAL'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = IT_FCAT.
ENDFORM.
FORM VALIDATE_LAYOUT .
CLEAR IT_layout.
IT_layout-colwidth_optimize = 'X'. " Optimization of Col width
IT_layout-coltab_fieldname = 'CELLCOLOR'.
ENDFORM.
2020 Nov 24 7:21 AM
2020 Nov 24 9:27 AM
There is no technical reason not use as many joins as you need. The idea that more than three is bad, is an unsubstatiated myth.
2020 Nov 24 7:32 AM
I guess you mean your LEFT OUTER JOIN on the material description table (MAKT) doesn't work well, it behaves like an INNER JOIN.
It's because the condition on the language should not be in the WHERE but in the ON, like this:
SELECT MARA~MATNR, MAKT~MAKTX,
MARC~WERKS, MARA~MATKL
INTO CORRESPONDING FIELDS OF TABLE @IT_MARAFINAL
FROM MARA
left outer JOIN MAKT ON MAKT~MATNR = MARA~MATNR
AND MAKT~SPRAS = '1' "<============ move it here
INNER JOIN MARC ON MARC~MATNR = MARA~MATNR
"""AND MAKT~MATNR = MARC~MATNR "<============ remove it
WHERE MARA~MATNR IN @S_MATNR
AND MARA~MATKL IN @S_MATKL
AND MARC~WERKS IN @S_WERKS.
What the SQL does with a join/on and a where, from the user perspective, is that it first does the JOIN and ON, then it applies the WHERE on the joined result.
As a rule-of-thumb, it makes no sense to have a WHERE condition on a LEFT OUTER JOIN table. But sometimes it can make sense to use IS NULL if you want a different WHERE condition whether the join has 0 line in the joined table (joined columns are null) or 1+ lines (joined columns are then usually not null).