12-07-2013 5:30 AM
hi,
my requirement is want to upload file in application server, from there using that file i want to create pr using bapi . I ll upload the file in application server using cg3z, now file is in app server. next step is i want to create pr using bapi. how i get file from app server and give in bapi. plz tell u r suggestions to solve ths...
Regards,
gopi.
12-07-2013 8:41 AM
Hi GOPI,
data ls_string type string.
data lt_string type table of string.
For getting the file from the Applicaion server.
IF lv_INV_path IS NOT INITIAL. " File Path with File name.
OPEN DATASET lv_INV_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
if sy-subrc <> 0 .
exit.
endif.
DO.
READ DATASET lv_INV_path INTO ls_string.
IF sy-subrc = 0. " Always check the SUBRC value after read statement.
APPEND ls_string to lt_string.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET LV_INV_PATH . "Always close the Dataset after read or Write the file.
ENDIF.
Now your data come in the String table.
Now loop on the String table and split the column one by one. Sequence must be same as the file sequence.
If any furthur issue let me know.
Regards.
Nishant Bansal
12-07-2013 5:51 AM
Hi Gopi,
Create a program in your application server and assign a tcode for that, call that tcode once the file has been uploaded in cg3z, and keep your logics there and create PR through below BAPI.
Use BAPI_REQUISTION_CREATE
call function 'BAPI_REQUISITION_CREATE'
exporting
skip_items_with_error = 'X'
importing
number = h_banfn
tables
requisition_items = req_item
requisition_account_assignment = req_acct
requisition_item_text = req_text
return = return
exceptions
others = 0.
Other related Bapis for purchase requisition are BAPI_REQUISITION_GETDETAIL and BAPI_REQUISTION_CHANGE.
Regards,
Venkat
12-07-2013 7:59 AM
Gopi you just have to read file from application server using open dataset etc and call your create bapi after that
12-07-2013 10:27 AM
hi nanbeet,
i ll paste one sample program. lts not for creating pr. just checking whether file is uploading in app server. whether the same step want to follow for create pr? give ur suggestions.
Regards,
gopi
12-07-2013 11:12 AM
Hi Gopi,
follow the steps as clearly explained by Nishant.
You copy paste program is not picking the file from the application server
You are commented the function module.
1. follow the steps of Nishant
2. get the all file data into the internal table.
3. Fill the BAPI structure fields to create the PR
4. Call the BAPI
Thanks,
Kiran
02-10-2023 5:21 PM
hi ,
this is Mubashir
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'READ DATASET GV_FILE INTO lv_data.
i am getting error here can you please help me what should be taken target path and in exel sheet how the data should be
12-07-2013 8:41 AM
Hi GOPI,
data ls_string type string.
data lt_string type table of string.
For getting the file from the Applicaion server.
IF lv_INV_path IS NOT INITIAL. " File Path with File name.
OPEN DATASET lv_INV_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
if sy-subrc <> 0 .
exit.
endif.
DO.
READ DATASET lv_INV_path INTO ls_string.
IF sy-subrc = 0. " Always check the SUBRC value after read statement.
APPEND ls_string to lt_string.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET LV_INV_PATH . "Always close the Dataset after read or Write the file.
ENDIF.
Now your data come in the String table.
Now loop on the String table and split the column one by one. Sequence must be same as the file sequence.
If any furthur issue let me know.
Regards.
Nishant Bansal
12-07-2013 10:25 AM
hi nishant,
i get the value in string table. after that wat to do. i ll paste my code plz suggest how to do this.
DATA: GV_FILE TYPE RLGRAP-filename.
DATA:LV_STRING TYPE TABLE OF string.
data:lv_data type string.
PARAMETERS:P_FILE TYPE SAPB-sappfad.
data:g_file type ibipparms-path.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = g_file
.
P_FILE = G_FILE.
START-OF-SELECTION.
* CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
* EXPORTING
* path = p_file
* TARGETPATH = 'T_FILE'
* EXCEPTIONS
* ERROR_FILE = 1
* OTHERS = 2
* .
* IF sy-subrc <> 0.
** TRANSFER P1_FILE TO P_FILE.
** Implement suitable error handling here
* MESSAGE 'UPLOAD SUCCESS' TYPE 'I'.
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
EXPORTING
path = P_FILE
TARGETPATH = '.\SAAAM.CSV'
EXCEPTIONS
ERROR_FILE = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
GV_FILE = 'SAAAM.CSV'.
IF GV_FILE IS NOT INITIAL.
OPEN DATASET GV_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-subrc NE 0.
MESSAGE 'UNABLE TO OPEN THE FILE ' TYPE 'I'.
ENDIF.
DO.
READ DATASET GV_FILE INTO LV_data.
*
IF SY-subrc = 0.
* loop at LV_STRING into lv_data.
append LV_DATA to LV_STRING.
else.
EXIT.
ENDIF.
ENDDO.
* ENDLOOP.
CLOSE DATASET GV_FILE.
ENDIF.
in above the value is coming to the it or in wa table. thats fine . after this wat i want to do.how i use bapi for this. i know BAPI_REQUISITION_CREATE is used to create pr.
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
EXPORTING
SKIP_ITEMS_WITH_ERROR =
AUTOMATIC_SOURCE = 'X'
IMPORTING
NUMBER =
TABLES
requisition_items =
REQUISITION_ACCOUNT_ASSIGNMENT =
REQUISITION_ITEM_TEXT =
REQUISITION_LIMITS =
REQUISITION_CONTRACT_LIMITS =
REQUISITION_SERVICES =
REQUISITION_SRV_ACCASS_VALUES =
RETURN =
REQUISITION_SERVICES_TEXT =
REQUISITION_ADDRDELIVERY =
EXTENSIONIN =
* .
i call this bapi. After this how i want to give value for this.for requstition items wat i want to give. how i want connect that file with this bapi..
Regards,
Gopi
12-07-2013 5:43 PM
Hi Gopi,
Suppose your final table contain 5 fields. " Its just example.
types: begin of ty_
matnr
maktx
end of ....
loop at lt_String into ls_string.
split at ls_String into wa_itab-matnr wa_itab-maktx . . " Separator you will decide explictly
append wa_itab to it_itab. " Now your data comes into your internal table
endloop.
Regards.
Nishant Bansal
12-09-2013 4:19 AM
hi nishant,
value is coming in internal table. there is no problem. but how i ll call this values into bapi. give one example .
12-09-2013 4:57 AM
Gopi whatever data you are getting you need to pass to BAPI call..Check a where used lis tof BAPI for sample code if available
02-10-2023 5:22 PM
hi ,
this is Mubashir
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'READ DATASET GV_FILE INTO lv_data.
i am getting error here can you please help me what should be taken target path and in exel sheet how the data should be
12-09-2013 9:24 AM
hi,
Now code is working. Thanks for every one for Your valuable suggestions. I ll past my code here.
types: begin of st,
material TYPE matnr,
qnty TYPE BAMNG,
plant TYPE EWERK,
doc_type type BBSRT,
del_date type EINDT,
end of st.
data: it1 type table of st,
wa1 type st.
FIELD-SYMBOLS:<fs> TYPE string,<ls_data>,
<fs_f> TYPE any.
DATA: GV_FILE TYPE RLGRAP-filename.
DATA:LV_STRING TYPE TABLE OF string.
data:lv_data type string.
PARAMETERS:P_FILE TYPE SAPB-sappfad.
data:g_file type ibipparms-path.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = g_file
.
P_FILE = G_FILE.
START-OF-SELECTION.
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
EXPORTING
path = P_FILE
TARGETPATH = '.\SAAAM.CSV'
EXCEPTIONS
ERROR_FILE = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
GV_FILE = 'SAAAM.CSV'.
IF GV_FILE IS NOT INITIAL.
OPEN DATASET GV_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-subrc NE 0.
MESSAGE 'UNABLE TO OPEN THE FILE ' TYPE 'I'.
ENDIF.
DO.
READ DATASET GV_FILE INTO lv_data.
IF SY-subrc ne 0.
EXIT.
else.
CLEAR LV_STRING.
SPLIT lv_data at ',' into table LV_STRING.
loop at LV_STRING ASSIGNING <FS>.
ASSIGN COMPONENT sy-tabix of STRUCTURE wa1 to <fs_f>.
if sy-subrc = 0.
<fs_f> = <fs>.
ENDIF.
AT LAST.
APPEND WA1 TO IT1.
ENDAT.
ENDLOOP.
ENDIF.
ENDDO.
*loop at wa1 to it1.
*ENDDO.
CLOSE DATASET GV_FILE.
ENDIF.
DATA: ITEMS TYPE bapiebanc.
DATA: RET TYPE STANDARD TABLE OF bapireturn,
WA_RET TYPE bapireturn.
DATA:ITEM TYPE STANDARD TABLE OF bapiebanc.
LOOP AT IT1 INTO WA1.
ITEMs-MATERIAL = WA1-material.
ITEMs-PLANT = WA1-PLANT.
ITEMs-QUANTITY = WA1-qnty.
ITEMs-doc_type = WA1-doc_type.
ITEMs-DELIv_DATE = WA1-del_date.
APPEND ITEMS TO ITEM.
ENDLOOP.
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
TABLES
requisition_items = item
RETURN = ret .
loop at ret into wa_ret.
MESSAGE WA_RET type wa_ret-type.
ENDLOOP.
Regards,
Gopi
02-10-2023 5:16 PM
hi gopi,
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'READ DATASET GV_FILE INTO lv_data.
i am getting error here can you please help me what should be taken target path and in exel sheet how the data should be