The source code is as follows:
*&---------------------------------------------------------------------*
*& Report ZSTATUS_INITIAL_LOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zstatus_initial_load.
TYPES:
BEGIN OF ty_sel_tab,
sign TYPE ddsign,
option TYPE ddoption,
low TYPE string,
high TYPE string,
END OF ty_sel_tab .
TYPES:
tt_sel_tab TYPE STANDARD TABLE OF ty_sel_tab .
DATA: lt_tj30 TYPE STANDARD TABLE OF tj30,
lv_valid_found TYPE abap_bool,
lt_option TYPE tt_sel_tab,
lt_table TYPE STANDARD TABLE OF zorder_guid.
SELECT stsma stonr INTO CORRESPONDING FIELDS OF TABLE lt_tj30 FROM tj30.
LOOP AT lt_tj30 ASSIGNING FIELD-SYMBOL(<tj30>).
AT NEW stsma.
lv_valid_found = abap_false.
ENDAT.
IF <tj30>-stonr IS NOT INITIAL.
lv_valid_found = abap_true.
ENDIF.
AT END OF stsma.
IF lv_valid_found = abap_true.
DATA(ls_option) = VALUE ty_sel_tab( sign = 'I' option = 'EQ' low = <tj30>-stsma ).
APPEND ls_option TO lt_option.
ENDIF.
ENDAT.
ENDLOOP.
SELECT guid INTO CORRESPONDING FIELDS OF TABLE lt_table FROM crmd_orderadm_h AS a INNER JOIN crm_jsto AS b
ON a~guid = b~objnr WHERE b~stsma IN lt_option.
DELETE FROM zorder_guid.
INSERT zorder_guid FROM TABLE lt_table.
COMMIT WORK AND WAIT.
WRITE: / 'table inserted'.
BREAK-POINT.
The main function of this ABAP program is to retrieve data from two SAP CRM data tables and insert data that meets specific conditions into a custom data table. The program also includes some control logic for selecting data that meets the conditions and performing submission operations.
Let me explain in detail what this program does and provide an example:
-
The program starts :
REPORT zstatus_initial_load.
: This line specifies the name of the program.
-
Type definition :
- After the program starts, two data structures (TYPES) are defined. The first one is
ty_sel_tab
used to store information about query selection conditions, including signature (sign), option (option), lower limit (low) and upper limit (high). The second one istt_sel_tab
, isty_sel_tab
a standard table type of type.
- After the program starts, two data structures (TYPES) are defined. The first one is
-
Data statement :
DATA
Statements are used to declare various data tables and variables, includinglt_tj30
,lv_valid_found
,lt_option
andlt_table
.
-
Data query :
SELECT
statementtj30
selects data from a table and stores the results inlt_tj30
the table.
-
Loop processing :
- Use
LOOP
the statement to iterate throughlt_tj30
the data in the table. In each iteration, useAT NEW stsma
andAT END OF stsma
control logic to perform certain operations.
- Use
-
Condition check :
- In the loop, the program checks to see
<tj30>-stonr
if is empty. If not empty, setslv_valid_found
to true (abap_true
).
- In the loop, the program checks to see
-
Data filtering :
- Within
AT END OF stsma
the control logic, iflv_valid_found
is true, the program creates a selection condition that matches the specified criterials_option
and then appends it tolt_option
the table.
- Within
-
Second data query :
- After the loop ends, the program executes the second
SELECT
statement, selects data fromcrmd_orderadm_h
table andcrm_jsto
table, and stores the result inlt_table
table. This query uses the selection criteria built earlierlt_option
.
- After the loop ends, the program executes the second
-
Data operations :
-
DELETE FROM zorder_guid.
: Clearzorder_guid
the custom data table named. -
INSERT zorder_guid FROM TABLE lt_table.
:lt_table
Insert data from the table intozorder_guid
the table. -
COMMIT WORK AND WAIT.
: Commit the database transaction.
-
-
Outputs and interrupts :
-
WRITE: / 'table inserted'.
: Output a text message on the screen indicating that the data has been inserted. -
BREAK-POINT.
: Insert breakpoints for debugging during program execution.
-
Now, let's use an example to illustrate what the program does:
Suppose you manage customer order data in a SAP CRM system. tj30
The table contains order status information, crmd_orderadm_h
and the and crm_jsto
tables contain order details. You want to tj30
select order statuses from a table that match certain criteria and insert the details of those orders into a custom table zorder_guid
.
For example, you want to select all orders with an order status of 'Approved'. After the program executes, it iterates through tj30
the table, finds all orders with status 'Approved', and inserts their details into zorder_guid
the table. Finally, the message 'table inserted' will appear on the screen, indicating that the operation is complete.
This is a simple example of how a program can select data from one table and insert it into another table based on selection criteria. In actual applications, the selection conditions and data tables in the program can be modified according to specific business needs to achieve different data processing operations.