ABAP Select data from SAP table CGHOFCPROJRESACT into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP CGHOFCPROJRESACT table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to CGHOFCPROJRESACT. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the CGHOFCPROJRESACT table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_CGHOFCPROJRESACT TYPE STANDARD TABLE OF CGHOFCPROJRESACT, WA_CGHOFCPROJRESACT TYPE CGHOFCPROJRESACT, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <CGHOFCPROJRESACT> TYPE CGHOFCPROJRESACT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CGHOFCPROJRESACT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CGHOFCPROJRESACT INTO TABLE IT_CGHOFCPROJRESACT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CGHOFCPROJRESACT * INTO TABLE @DATA(IT_CGHOFCPROJRESACT2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_CGHOFCPROJRESACT INDEX 1 INTO DATA(WA_CGHOFCPROJRESACT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CGHOFCPROJRESACT ASSIGNING <CGHOFCPROJRESACT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CGHOFCPROJRESACT>-MANDT = 1.
<CGHOFCPROJRESACT>-UPSTREAMPROJECTID = 1.
<CGHOFCPROJRESACT>-STARTDATE = 1.
<CGHOFCPROJRESACT>-ENDDATE = 1.
<CGHOFCPROJRESACT>-NETWORKOBJECTID = 1.
ENDLOOP. LOOP AT IT_CGHOFCPROJRESACT INTO WA_CGHOFCPROJRESACT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CGHOFCPROJRESACT-NETWORKOBJECTNAME, sy-vline,
WA_CGHOFCPROJRESACT-NETWORKMEDIUM, sy-vline,
WA_CGHOFCPROJRESACT-FORECASTRESULTTYPE, sy-vline,
WA_CGHOFCPROJRESACT-ALLOCATIONFREQUENCYCODE, sy-vline,
WA_CGHOFCPROJRESACT-FORECASTRESULTDATE, sy-vline,
WA_CGHOFCPROJRESACT-FORECASTRESULTVALUE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CGHOFCPROJRESACT you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_CGHOFCPROJRESACT TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_CGHOFCPROJRESACT INTO WA_CGHOFCPROJRESACT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit GHONO, internal->external for field NETWORKOBJECTNAME CALL FUNCTION 'CONVERSION_EXIT_GHONO_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-NETWORKOBJECTNAME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-NETWORKOBJECTNAME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GHOFC, internal->external for field PRODUCTIONNETWORKNAME CALL FUNCTION 'CONVERSION_EXIT_GHOFC_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-PRODUCTIONNETWORKNAME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-PRODUCTIONNETWORKNAME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNITOFMEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-UNITOFMEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-UNITOFMEASURE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSP, internal->external for field WBSELEMENT CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-WBSELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-WBSELEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-COSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-COSTCENTER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PROFITCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CGHOFCPROJRESACT-PROFITCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CGHOFCPROJRESACT-PROFITCENTER.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_CGHOFCPROJRESACT_STR,
MANDT TYPE STRING,
UPSTREAMPROJECTID TYPE STRING,
STARTDATE TYPE STRING,
ENDDATE TYPE STRING,
NETWORKOBJECTID TYPE STRING,
NETWORKOBJECTNAME TYPE STRING,
NETWORKMEDIUM TYPE STRING,
FORECASTRESULTTYPE TYPE STRING,
ALLOCATIONFREQUENCYCODE TYPE STRING,
FORECASTRESULTDATE TYPE STRING,
FORECASTRESULTVALUE TYPE STRING,
DOWNSTREAMFORECASTRESULTVALUE TYPE STRING,
PROJECTNAME TYPE STRING,
PROJECTDESCRIPTION TYPE STRING,
UPSTREAMPROJEFFCTVDATETO TYPE STRING,
UPSTREAMPROJEFFCTVDATEFROM TYPE STRING,
UPSTREAMPROJSTATUSOBJECT TYPE STRING,
SCENARIOID TYPE STRING,
SCENARIONAME TYPE STRING,
SCENARIODESCRIPTION TYPE STRING,
SCENARIOSTATE TYPE STRING,
PRODUCTIONNETWORKID TYPE STRING,
PRODUCTIONNETWORKDESCRIPTION TYPE STRING,
PRODUCTIONNETWORKNAME TYPE STRING,
NETWORKOBJECTTYPE TYPE STRING,
NETWORKOBJECTDESCRIPTION TYPE STRING,
NETWORKOBJECTEFFECTIVEDATEFROM TYPE STRING,
NETWORKOBJECTEFFECTIVEDATETO TYPE STRING,
FORECASTTYPE TYPE STRING,
FORECASTTYPEDESCRIPTION TYPE STRING,
FORECASTDATE TYPE STRING,
DISPLAYTIMEZONE TYPE STRING,
NETWORKCHAINSOURCEFLAG TYPE STRING,
UNITOFMEASURE TYPE STRING,
WBSELEMENT TYPE STRING,
COSTCENTER TYPE STRING,
PROFITCENTER TYPE STRING,
STATUSOBJECTNUMBER TYPE STRING,
USERSTATUSPROFILE TYPE STRING,
NETWORKMEDIUMDESCRIPTION TYPE STRING,
CALENDARDATE TYPE STRING,
CALENDARYEAR TYPE STRING,
CALENDARMONTH TYPE STRING,
CALENDARDAY TYPE STRING,
UPSTREAMPROJECTSTATUS TYPE STRING,
PROJECTSCENARIOEXTERNALNAME TYPE STRING,
OBJECTTYPE TYPE STRING,
EXTERNALFORECASTRESULTTYPE TYPE STRING,
OBJECTORDERNUMBER TYPE STRING,
OBJECTSTATUS TYPE STRING,
OBJECTINDICATOR TYPE STRING,
SYSTEMSTATUS TYPE STRING,
CALENDARMONTHSHORTNAME TYPE STRING,END OF T_EKKO_STR. DATA: WA_CGHOFCPROJRESACT_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_CGHOFCPROJRESACT_STR-MANDT sy-vline
WA_CGHOFCPROJRESACT_STR-UPSTREAMPROJECTID sy-vline
WA_CGHOFCPROJRESACT_STR-STARTDATE sy-vline
WA_CGHOFCPROJRESACT_STR-ENDDATE sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTID sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTNAME sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKMEDIUM sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTRESULTTYPE sy-vline
WA_CGHOFCPROJRESACT_STR-ALLOCATIONFREQUENCYCODE sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTRESULTDATE sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTRESULTVALUE sy-vline
WA_CGHOFCPROJRESACT_STR-DOWNSTREAMFORECASTRESULTVALUE sy-vline
WA_CGHOFCPROJRESACT_STR-PROJECTNAME sy-vline
WA_CGHOFCPROJRESACT_STR-PROJECTDESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-UPSTREAMPROJEFFCTVDATETO sy-vline
WA_CGHOFCPROJRESACT_STR-UPSTREAMPROJEFFCTVDATEFROM sy-vline
WA_CGHOFCPROJRESACT_STR-UPSTREAMPROJSTATUSOBJECT sy-vline
WA_CGHOFCPROJRESACT_STR-SCENARIOID sy-vline
WA_CGHOFCPROJRESACT_STR-SCENARIONAME sy-vline
WA_CGHOFCPROJRESACT_STR-SCENARIODESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-SCENARIOSTATE sy-vline
WA_CGHOFCPROJRESACT_STR-PRODUCTIONNETWORKID sy-vline
WA_CGHOFCPROJRESACT_STR-PRODUCTIONNETWORKDESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-PRODUCTIONNETWORKNAME sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTTYPE sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTDESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTEFFECTIVEDATEFROM sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKOBJECTEFFECTIVEDATETO sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTTYPE sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTTYPEDESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-FORECASTDATE sy-vline
WA_CGHOFCPROJRESACT_STR-DISPLAYTIMEZONE sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKCHAINSOURCEFLAG sy-vline
WA_CGHOFCPROJRESACT_STR-UNITOFMEASURE sy-vline
WA_CGHOFCPROJRESACT_STR-WBSELEMENT sy-vline
WA_CGHOFCPROJRESACT_STR-COSTCENTER sy-vline
WA_CGHOFCPROJRESACT_STR-PROFITCENTER sy-vline
WA_CGHOFCPROJRESACT_STR-STATUSOBJECTNUMBER sy-vline
WA_CGHOFCPROJRESACT_STR-USERSTATUSPROFILE sy-vline
WA_CGHOFCPROJRESACT_STR-NETWORKMEDIUMDESCRIPTION sy-vline
WA_CGHOFCPROJRESACT_STR-CALENDARDATE sy-vline
WA_CGHOFCPROJRESACT_STR-CALENDARYEAR sy-vline
WA_CGHOFCPROJRESACT_STR-CALENDARMONTH sy-vline
WA_CGHOFCPROJRESACT_STR-CALENDARDAY sy-vline
WA_CGHOFCPROJRESACT_STR-UPSTREAMPROJECTSTATUS sy-vline
WA_CGHOFCPROJRESACT_STR-PROJECTSCENARIOEXTERNALNAME sy-vline
WA_CGHOFCPROJRESACT_STR-OBJECTTYPE sy-vline
WA_CGHOFCPROJRESACT_STR-EXTERNALFORECASTRESULTTYPE sy-vline
WA_CGHOFCPROJRESACT_STR-OBJECTORDERNUMBER sy-vline
WA_CGHOFCPROJRESACT_STR-OBJECTSTATUS sy-vline
WA_CGHOFCPROJRESACT_STR-OBJECTINDICATOR sy-vline
WA_CGHOFCPROJRESACT_STR-SYSTEMSTATUS sy-vline
WA_CGHOFCPROJRESACT_STR-CALENDARMONTHSHORTNAME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.