abap - Field "ZCRM_MLS2" is unknown Error - abap

I am getting a error of "Field "ZCRM_MLS2" is unknown." at Line 23. Do you guys have any idea? Thanks in advance.
REPORT zcrm_mls_program2.
DATA: lv_name_surname TYPE zcrm_dt_ml2,
lv_age TYPE zcrm_dt_ml1,
lv_done TYPE xfeld,
lt_alldata TYPE zcrm_mls2,
ls_data TYPE zcrm_mls2 .
SELECT * FROM zcrm_mls2
WHERE done IS INITIAL INTO #lt_alldata.
ENDSELECT.
IF sy-subrc is INITIAL .
MODIFY zcrm_mls3 FROM lt_alldata.
LOOP at zcrm_mls2 INTO ls_data. " <==== line number 23
ls_data-done = 'X'.
MODIFY zcrm_mls3 FROM ls_data.
ENDLOOP.
ENDIF.

Just fo fun
REPORT zcrm_mls_program2.
DATA: lt_alldata TYPE STANDARD TABLE OF zcrm_mls2 WITH EMPTY KEY,
ls_data TYPE zcrm_mls2.
*----------------------------------------------------------------------*
*1st version
SELECT * FROM zcrm_mls2
WHERE done = #space INTO #ls_data.
APPEND ls_data TO lt_alldata.
ENDSELECT.
IF sy-subrc IS INITIAL .
LOOP AT lt_alldata INTO ls_data.
ls_data-done = 'X'.
MODIFY zcrm_mls3 FROM ls_data.
ENDLOOP.
COMMIT WORK.
ENDIF.
*----------------------------------------------------------------------*
*2nd version
SELECT *
FROM zcrm_mls2
INTO TABLE #lt_alldata
WHERE done = #space
.
IF sy-subrc IS INITIAL .
LOOP AT lt_alldata INTO ls_data.
ls_data-done = 'X'.
MODIFY zcrm_mls3 FROM ls_data.
ENDLOOP.
COMMIT WORK.
ENDIF.
*----------------------------------------------------------------------*
*3rd version
SELECT *
FROM zcrm_mls2
INTO TABLE #lt_alldata
WHERE done = #space
.
IF sy-subrc IS INITIAL .
LOOP AT lt_alldata INTO ls_data.
ls_data-done = 'X'.
MODIFY lt_alldata INDEX sy-tabix FROM ls_data .
ENDLOOP.
MODIFY zcrm_mls3 FROM TABLE lt_alldata.
COMMIT WORK.
ENDIF.
*----------------------------------------------------------------------*
*4th version
SELECT *
FROM zcrm_mls2
INTO TABLE #lt_alldata
WHERE done = #space
.
IF sy-subrc IS INITIAL .
LOOP AT lt_alldata REFERENCE INTO DATA(lps_data).
lps_data->done = 'X'.
ENDLOOP.
MODIFY zcrm_mls3 FROM TABLE lt_alldata.
COMMIT WORK.
ENDIF.
*----------------------------------------------------------------------*
*5th version
SELECT *
FROM zcrm_mls2
INTO TABLE #lt_alldata
WHERE done = #space
.
IF sy-subrc IS INITIAL .
MODIFY lt_alldata FROM VALUE #( done = 'X' ) TRANSPORTING done WHERE done = space.
MODIFY zcrm_mls3 FROM TABLE lt_alldata.
COMMIT WORK.
ENDIF.

Related

What is reason why my second list for my ALV report not showing any info?

I am trying to create a classical list. Everything until At line-selection works. The problem that I have is with At line-selection. First, I execute the program and it shows me the parameter s_matnr, I then enter the
values (e.g. 500-100 - 500-400) and it gets me to the first list. After that, I choose one field by checking and I double-click on it. It then shows me another window and when I try to get to the second list that I've created it just doesn't output any info on the screen.
What I have to do is to get two tables, ekko and ekpo, and to display the info in a list. For that, I have tried to create a inner join between the two tables and then loop through them and write the info. Also, I have to calculate the total quantity of each Purchase order.
Could you help me out? Thank you!
The list has to look like this :
My lines of code :
TOP-OF-PAGE.
WRITE: / 'User:',sy-uname, 29 'Programe Name: ', sy-cprog,
/ 'Date: ', sy-datum.
ULINE.
TABLES mara.
TYPES : BEGIN OF ty_mara,
chck TYPE char1,
matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
ntgew TYPE mara-ntgew,
gewei TYPE mara-gewei,
spart TYPE mara-spart,
name TYPE string,
END OF ty_mara,
tt_mara TYPE STANDARD TABLE OF ty_mara.
TYPES: BEGIN OF ty_marc,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
END OF ty_marc.
TYPES:BEGIN OF ty_ab,
ebeln TYPE ekpo-ebeln,
lifnr TYPE ekko-lifnr,
bedat TYPE ekko-bedat,
ekorg TYPE ekko-ekorg,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
END OF ty_ab.
DATA:
gt_ab TYPE TABLE OF ty_ab,
gs_ab TYPE ty_ab.
TYPES: BEGIN OF ty_name,
cbx TYPE c,
cmatnr TYPE mara-matnr,
END OF ty_name.
DATA:
gv_var1 TYPE string VALUE 'Purchase order',
gv_var2 TYPE string VALUE 'Vendor',
gv_var3 TYPE string VALUE 'Document Date',
gv_var4 TYPE string VALUE 'Purchasing Org.',
gv_var5 TYPE string VALUE 'Purchasing Group',
gv_var6 TYPE string VALUE 'Company Code',
gv_quantity TYPE ekpo-menge VALUE 0.
DATA:
gv_v1 TYPE string VALUE 'Item',
gv_v2 TYPE string VALUE 'Delivery Date',
gv_v3 TYPE string VALUE 'PO Quantity',
gv_v4 TYPE string VALUE 'Unit',
gv_v5 TYPE string VALUE 'Net Price'.
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
bedat TYPE ekko-bedat,
ekorg TYPE ekko-ekorg,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
END OF ty_ekko.
TYPES:BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
END OF ty_ekpo.
DATA: gt_mara TYPE TABLE OF ty_mara,
gs_mara TYPE ty_mara,
gt_marc TYPE TABLE OF ty_marc,
gs_marc TYPE ty_marc,
gt_popup TYPE ty_marc,
gv_string TYPE string,
gv_line TYPE i,
gs_name TYPE ty_name,
gt_name TYPE TABLE OF ty_name,
gt_ekko TYPE TABLE OF ty_ekko,
gs_ekko TYPE ty_ekko,
gt_ekpo TYPE TABLE OF ty_ekpo,
gs_ekpo TYPE ty_ekpo.
SELECT-OPTIONS s_matnr FOR mara-matnr.
START-OF-SELECTION.
SET PF-STATUS 'DIALOG'.
SELECT a~matnr, a~ntgew, a~gewei, a~spart, b~maktx
FROM mara AS a
INNER JOIN makt AS b
ON a~matnr = b~matnr
INTO CORRESPONDING FIELDS OF TABLE #gt_mara
WHERE a~matnr IN #s_matnr
AND b~spras = 'E'.
WRITE: AT 3 'Material', AT 30 'Material Description', AT 60 'Net Weight',
AT 80 'Unit', AT 85 'Division'.
LOOP AT gt_mara INTO gs_mara.
IF gs_mara-ntgew < 10.
WRITE: / gs_name-cbx AS CHECKBOX,
gs_mara-matnr COLOR 4,
gs_mara-maktx COLOR 4,
gs_mara-ntgew COLOR 4,
gs_mara-gewei COLOR 4,
gs_mara-spart COLOR 4.
ELSE.
WRITE: / gs_name-cbx AS CHECKBOX,
gs_mara-matnr COLOR COL_NEGATIVE,
gs_mara-maktx COLOR COL_NEGATIVE,
gs_mara-ntgew COLOR COL_NEGATIVE,
gs_mara-gewei COLOR COL_NEGATIVE,
gs_mara-spart COLOR COL_NEGATIVE.
ENDIF.
ENDLOOP.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN'DISPLAY'.
SET PF-STATUS 'POP'.
SET TITLEBAR 'Titlu'.
WINDOW STARTING AT 5 3 ENDING AT 40 10.
CLEAR: gs_mara,gv_string.
DO .
READ LINE sy-index FIELD VALUE gs_name-cbx INTO gs_name-cbx.
IF sy-subrc = 0.
IF gs_name-cbx = 'X'.
READ LINE sy-index FIELD VALUE gs_mara-matnr INTO gs_name-cmatnr.
SELECT marc~matnr marc~werks
INTO CORRESPONDING FIELDS OF TABLE gt_marc
FROM marc
WHERE marc~matnr LIKE gs_name-cmatnr.
IF sy-subrc = 0.
LOOP AT gt_marc INTO gs_marc.
WRITE: / gs_marc-matnr, gs_marc-werks.
ENDLOOP.
ELSE .
MESSAGE e208(00) WITH 'No records found!'.
ENDIF.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
WRITE:/ '' .
ENDCASE.
AT LINE-SELECTION.
GET CURSOR LINE gv_line.
READ LINE gv_line FIELD VALUE gs_mara-matnr INTO gs_name-cmatnr.
SELECT
c~lifnr
c~bedat
c~ekorg
c~ekgrp
c~bukrs
c~ebeln
d~ebelp
d~aedat
d~menge
d~meins
d~netpr
FROM ekko AS c
INNER JOIN ekpo AS d
ON c~ebeln = d~ebeln
INTO CORRESPONDING FIELDS OF TABLE gt_ab
WHERE d~matnr = gs_name-cmatnr .
LOOP AT gt_ab INTO gs_ab.
IF sy-subrc = 0.
gv_quantity = 0.
ULINE.
WRITE:/
gs_ekko-ebeln UNDER gv_var1 COLOR 6,
gs_ekko-lifnr UNDER gv_var2 COLOR 6,
gs_ekko-bedat UNDER gv_var3 COLOR 6,
gs_ekko-ekorg UNDER gv_var4 COLOR 6,
gs_ekko-ekgrp UNDER gv_var5 COLOR 6,
gs_ekko-bukrs UNDER gv_var6 COLOR 6.
WRITE:/
gs_ekpo-ebelp UNDER gv_v1 ,
gs_ekpo-aedat UNDER gv_v2 ,
gs_ekpo-menge UNDER gv_v3 ,
gs_ekpo-meins UNDER gv_v4 ,
gs_ekpo-netpr UNDER gv_v5 .
gv_quantity = gv_quantity + gs_ekpo-menge.
WRITE:/ 'Total Quantity=' UNDER gv_v3 COLOR 3, gv_quantity COLOR 3.
ELSE.
MESSAGE e208(00) WITH 'Nu a fost gasit!'.
ENDIF.
ENDLOOP.
I guess you need to debug your code to check what's going on, what the exact issue is.
Here is a Minimal Reproducible Example, which demonstrates that there's basically no issue from the different list levels:
REPORT.
TYPES ty_matnr TYPE c LENGTH 10.
DATA matnr TYPE ty_matnr.
SELECT-OPTIONS s_matnr FOR matnr.
TOP-OF-PAGE.
WRITE: / 'User:',sy-uname, 29 'Programe Name: ', sy-cprog,
/ 'Date: ', sy-datum.
ULINE.
START-OF-SELECTION.
WRITE / 'Enter DISPLAY in the Command Field and press Enter'.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN'DISPLAY'.
WINDOW STARTING AT 5 3 ENDING AT 40 10.
matnr = '500-100'.
WRITE / matnr.
matnr = '500-400'.
WRITE / matnr.
matnr = '700-220'.
WRITE / matnr.
ENDCASE.
AT LINE-SELECTION.
DATA gv_line TYPE i.
GET CURSOR LINE gv_line.
DATA matnr2 TYPE ty_matnr.
READ LINE gv_line FIELD VALUE matnr INTO matnr2.
WRITE : / 'Second list. Selected line is', matnr2.

Loop in a Loop with index less than the stopped one

I have the following problem and I need an idea how to overcome?
I have 2 identical ITABs: ITAB1 and ITAB2 with 60 records.
I am looping in the 1st ITAB and when I am finding a record I am looping in the 2nd ITAB with INDEX = sy-tabix of the 1st one:
LOOP at ITAB1 where COL = '001'.
lv_tabix = sy-tabix.
* Do STH.
LOOP at ITAB2 FROM lv_tabix
* do sth
EXIT.
ENDCASE.
ENDCASE.
Lets suppose that I am looping the 2nd ITAB with lv_tabix = 17 and, I am exiting from the 2nd when its tabix=22.
So I am returning in the 1st ITAB do sth and, I am starting the loop of the 2nd ITAB with lv_tabix=21.
I have noticed that the loop of the 2nd ITAB cannot start from a record (21) which is less than the one it was stopped (22).
Am I right?
How can I overcome this problem?
Thanks
Elias
Cannot reproduce your problem.
DATA(table_1) = VALUE string_table( ( `A` ) ( `B` ) ( `C` ) ( `D` ) ).
DATA(table_2) = VALUE string_table( ( `A` ) ( `B` ) ( `C` ) ( `D` ) ).
LOOP AT table_1 INTO DATA(row_1).
DATA(start_index) = sy-tabix.
LOOP AT table_2 INTO DATA(row_2) FROM start_index.
IF row_2 = `C`.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
works fine, although in the first outer loop iteration it exits the inner loop at sy-tabix = 3 and in the second outer loop iteration restarts the inner loop with the lower start_index = 2.

Checkbox multiple selection filter

I want to filter the data into my program depending what checkbox is selected or not.
parameters: p_z1 as checkbox DEFAULT 'X' ,
p_z2 as checkbox.
selection-screen end of block b4.
So if one of these two is selected or if both are selected how can I filter my data?
select single * from mara where matnr = pv_matnr
and "if checkbox one is selected" where matkl = t023-matkl.
"if checkbox two is selected" where matkl = v023-matkl.
You can prepare dynamic where clause -
DATA : lv_query TYPE string.
CONCATENATE 'MATNR = PV_MATNR' lv_query INTO lv_query.
IF p_z1 = 'X'.
CONCATENATE lv_query 'AND MATKL = T023-MATKL' INTO lv_query SEPARATED BY space.
ENDIF.
IF p_z2 = 'X'.
CONCATENATE lv_query 'AND MATKL = V023-MATKL' INTO lv_query SEPARATED BY space.
ENDIF.
SELECT SINGLE * FROM mara WHERE (lv_query).
"Dynamic" queries are to be avoided as far as possible, just to make it easier to check the code against possible SQL injection attacks (with SELECT … WHERE (lv_query), there could be a Denial-of-Service attack with an empty lv_query empty). So I would write the code by divScorp as follows:
parameters: p_z1 as checkbox DEFAULT 'X' ,
p_z2 as checkbox,
pv_matnr TYPE mara-matnr.
DATA: t023 TYPE t023, v023 TYPE v023, mara TYPE mara.
DATA range_matkl TYPE RANGE OF mara-matkl.
CLEAR range_matkl.
IF p_z1 = 'X'.
APPEND VALUE #( sign = 'I' option = 'EQ' low = t023-matkl ) TO range_matkl.
ENDIF.
IF p_z2 = 'X'.
APPEND VALUE #( sign = 'I' option = 'EQ' low = v023-matkl ) TO range_matkl.
ENDIF.
SELECT SINGLE * FROM mara WHERE MATNR = PV_MATNR and matkl IN range_matkl.
PS: my code (and the one of divScorp) is non-sense because pureAbap algorithm is incorrect : in case p_z1 and p_z2 are both 'X', then there's the risk that the SELECT returns nothing if t023-matkl is different from v023-matkl. Maybe p_z1 and p_z2 should be converted into radio buttons? (only one of the two can be selected?)
You can always use:
IF chck1 = 'X' and chck2 = 'X'.
SELECT ... WHERE both.
ELSEIF chck1 = 'X'.
SELECT ... WHERE ...
ELSEIF chck2 = 'X'.
SELECT ... WHERE ...
ENDIF.
But I guess that's not what you wanted to do. Not the most elegant way but hey - it works.

am getting this error: Incorrect nesting before the end of the program the structure introduced by if must be concluded by endif

*&---------------------------------------------------------------------*
*& Report ZFOR_ALL_ENTRYS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zfor_all_entrys NO STANDARD PAGE HEADING.
TYPES : BEGIN OF ty_likp,
vbeln TYPE vbeln_vl,
ernam TYPE ernam,
erdat TYPE erdat,
kunnr TYPE kunnr,
kunag TYPE kunag,
END OF ty_likp.
TYPES : BEGIN OF ty_lips,
vbeln TYPE vbeln_vl,
posnr TYPE posnr_vl,
pstyv TYPE pstyv_vl,
matnr TYPE matnr,
charg TYPE charg_d,
meins TYPE meins,
END OF ty_lips.
DATA : it_likp TYPE TABLE OF ty_likp,
it_lips TYPE TABLE OF ty_lips.
DATA : wa_likp TYPE ty_likp,
wa_lips TYPE ty_lips.
IF sy-subrc IS INITIAL.
SELECT vbeln
ernam
erdat
kunnr
kunag FROM likp
INTO TABLE it_likp
WHERE ernam = 'bollinger'.
IF sy-subrc IS INITIAL.
SELECT vbeln
posnr
pstyv
matnr
charg
meins FROM lips
INTO TABLE it_lips
FOR ALL ENTRIES IN it_likp
WHERE vbeln = it_likp-vbeln.
IF sy-subrc IS INITIAL.
LOOP AT it_likp INTO wa_likp.
LOOP AT it_lips INTO wa_lips WHERE vbeln = wa_likp-vbeln.
WRITE : wa_likp-vbeln,
wa_likp-erdat,
wa_likp-ernam,
wa_likp-kunnr,
wa_likp-kunag,
wa_lips-posnr,
wa_lips-pstyv,
wa_lips-matnr,
wa_lips-charg,
wa_lips-meins.
ENDLOOP.
ENDLOOP.
ENDIF.
Each IF statement needs an ENDIF.
Every IF sy-subrc IS INITIAL. must be closed ENDIF.
I think correct code is below.
IF sy-subrc IS INITIAL.
SELECT vbeln
ernam
erdat
kunnr
kunag FROM likp
INTO TABLE it_likp
WHERE ernam = 'bollinger'.
ENDIF.
IF sy-subrc IS INITIAL.
SELECT vbeln
posnr
pstyv
matnr
charg
meins FROM lips
INTO TABLE it_lips
FOR ALL ENTRIES IN it_likp
WHERE vbeln = it_likp-vbeln.
ENDIF.
IF sy-subrc IS INITIAL.
LOOP AT it_likp INTO wa_likp.
LOOP AT it_lips INTO wa_lips WHERE vbeln = wa_likp-vbeln.
WRITE: wa_likp-vbeln,
wa_likp-erdat,
wa_likp-ernam,
wa_likp-kunnr,
wa_likp-kunag,
wa_lips-posnr,
wa_lips-pstyv,
wa_lips-matnr,
wa_lips-charg,
wa_lips-meins.
ENDLOOP.
ENDLOOP.
ENDIF.

Group invoices by entity, with LOOP AT

My program outputs a list with some invoice and details and I want them to appear by entity.
The list shows the entity number and name repeating in every line of the list, but I want it to appear grouped by.
e.g. there are 4 invoices: two from each entity, how to show the entity and all of the respective invoices and then the other entity, and so on?
The code I have is this one:
FORM select_data3 CHANGING lt_data LIKE gt_map1.
FIELD-SYMBOLS: <fs_main> TYPE zimposto_consumo.
SELECT a~belnr d~spart a~bldat a~waers c~wrbtr a~hwaer c~dmbtr
INTO CORRESPONDING FIELDS OF TABLE lt_data
FROM ( ( bkpf AS a
INNER JOIN bsis AS c ON c~belnr = a~belnr
AND buzei = 1 )
INNER JOIN vbrk AS d ON d~xblnr = c~belnr )
WHERE a~gjahr in gjahr.
LOOP AT lt_data ASSIGNING <fs_main>.
clear <fs_main>-kbetr.
clear <fs_main>-fwste.
clear <fs_main>-hwste.
SELECT SINGLE kbetr fwste hwste FROM bset
INTO (<fs_main>-kbetr, <fs_main>-fwste, <fs_main>-hwste)
WHERE belnr = <fs_main>-belnr.
clear <fs_main>-koart.
SELECT SINGLE koart kunnr FROM bseg
INTO (<fs_main>-koart, wa_bseg-kunnr)
WHERE belnr = <fs_main>-belnr.
IF <fs_main>-koart = 'D'.
SELECT SINGLE name1 FROM kna1
INTO (wa_bseg-name1)
WHERE kunnr = wa_bseg-kunnr.
IF sy-subrc = 0.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ sy-uline(137), / sy-vline NO-GAP,
2 'Entidade: ', wa_bseg-kunnr, wa_bseg-name1,
137 sy-vline NO-GAP, / sy-uline(137).
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/
sy-vline NO-GAP,
(16) <fs_main>-belnr NO-GAP,
sy-vline NO-GAP,
(16) <fs_main>-spart NO-GAP,
sy-vline NO-GAP,
(10) <fs_main>-bldat NO-GAP,
sy-vline NO-GAP.
perc = <fs_main>-kbetr / 10.
...
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
I used a block AT NEW ... ENDAT inside the block LOOP AT ... ENDLOOP.